@extends('common.admin_template')

@section('content')
    <div class="boxWidth">
        <h3>编辑商品分类</h3>
        @include('common.notice_msg')
        <form method="post" action="{{url('admin/cats/save')}}">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <input type="hidden" name="Cat[id]" value="{{$Cat->id}}">
        <div class="row editFormItem">
            <div class="col-xs-3"><span>分类</span></div>
            <div class="col-xs-8" id="nameBox"><input type="text" class="form-control" id="name" name="Cat[name]" value="{{$Cat->name}}"><div class="addInputNotice">请输入分类名称</div></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-3"><span>排序</span></div>
            <div class="col-xs-8" id="orderBox"><input type="text" id="order" class="form-control" name="Cat[order_id]" value="{{$Cat->order_id}}"></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-3"><button class="btn btn-primary addInputBtn" type="submit" id="formSubmit">更新</button></div>
            <div class="col-xs-8"></div>
        </div>
        </form>
    </div>
@stop
@section('js')
    <script>
        (function () {
            function hasError(id){
                var str =  $('#'+id).val().replace(/(^\s*)|(\s*$)/g, "");
                if(!str){
                    $('#'+id+'Box').addClass('has-error');
                    return 1;
                }
                return 0;
            }
            $('#formSubmit').on('click',function (e) {
                var sub = 0;
                if(hasError('name')){
                    sub = 1
                }
                if(hasError('order')){
                    sub = 1
                }
                if(sub){
                    e.preventDefault();
                }
            });

        })();
    </script>
@stop